module.exports = {
  devServer: {
    open: true, // 启动页面
    // Mock接口编写
    before (app) {
      // 用户池c
      let userPoor = [{
        username: 'dzkjdx',
        password: '123456'
      },
      {
        username: 'rcz',
        password: '123456'
      }
      ]
      // 注册接口
      app.get('/api/register', (req, res) => {
        const {
          username,
          password
        } = req.query
        const userlength = userPoor.filter(u => u.username === username).length
        if (userlength > 0) {
          res.json({
            success: false,
            message: '用户名已存在'
          })
        } else {
          res.json({
            success: true,
            message: '注册成功'
          })
        }
      })

      let tokenkey = 'jingdong'
      // 登录接口
      app.get('/api/login', (req, res) => {
        const {
          username,
          password
        } = req.query
        // 查看有没有此用户
        let flag = userPoor.some(u => {
          if (u.username === username && u.password === password) {
            return true
          }
        })
        console.log('flag', flag)
        if (flag) {
          res.json({
            code: 0,
            message: '登录成功',
            token: tokenkey + '-' + username + '-' + (new Date().getTime() + 60 * 60 * 1000)
          })
        } else {
          res.json({
            code: 1,
            message: '账号或密码错误',
            flag: flag
          })
        }
      })

      // 轮播图数据接口
      app.get('/api/banner', (req, res) => {
        res.json({
          data: [{
            url: 'https://h5.m.taobao.com/',
            image: 'https://img.alicdn.com/simba/img/TB1UAlqTsbpK1RjSZFySut_qFXa.jpg'
          },
          {
            url: 'https://h5.m.taobao.com/',
            image: 'https://aecpm.alicdn.com/tps/i1/TB1r4h8JXXXXXXoXXXXvKyzTVXX-520-280.jpg'
          },
          {
            url: 'https://h5.m.taobao.com/',
            image: 'https://aecpm.alicdn.com/tps/i2/TB10vPXKpXXXXacXXXXvKyzTVXX-520-280.jpg'
          }
          ]
        })
      })

      // 滚动分类接口
      app.get('/api/rollinglist', (req, res) => {
        res.json({
          data: [
            [{
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t1/29256/16/1420/4265/5c120d2aE83ef9fd4/ca89a8718704215c.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t1/29256/16/1420/4265/5c120d2aE83ef9fd4/ca89a8718704215c.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t1/29256/16/1420/4265/5c120d2aE83ef9fd4/ca89a8718704215c.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t1/29256/16/1420/4265/5c120d2aE83ef9fd4/ca89a8718704215c.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t1/29256/16/1420/4265/5c120d2aE83ef9fd4/ca89a8718704215c.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t1/29256/16/1420/4265/5c120d2aE83ef9fd4/ca89a8718704215c.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t1/29256/16/1420/4265/5c120d2aE83ef9fd4/ca89a8718704215c.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t1/29256/16/1420/4265/5c120d2aE83ef9fd4/ca89a8718704215c.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t1/29256/16/1420/4265/5c120d2aE83ef9fd4/ca89a8718704215c.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t1/29256/16/1420/4265/5c120d2aE83ef9fd4/ca89a8718704215c.png.webp',
              label: '分类一'
            }
            ],
            [{
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t16828/63/2653634926/5662/d18f6fa1/5b03b779N5c0b196f.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t16828/63/2653634926/5662/d18f6fa1/5b03b779N5c0b196f.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t16828/63/2653634926/5662/d18f6fa1/5b03b779N5c0b196f.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t16828/63/2653634926/5662/d18f6fa1/5b03b779N5c0b196f.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t16828/63/2653634926/5662/d18f6fa1/5b03b779N5c0b196f.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t16828/63/2653634926/5662/d18f6fa1/5b03b779N5c0b196f.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t16828/63/2653634926/5662/d18f6fa1/5b03b779N5c0b196f.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t16828/63/2653634926/5662/d18f6fa1/5b03b779N5c0b196f.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t16828/63/2653634926/5662/d18f6fa1/5b03b779N5c0b196f.png.webp',
              label: '分类一'
            },
            {
              url: 'https://www.jd.com/',
              image: '//m.360buyimg.com/mobilecms/s120x120_jfs/t16828/63/2653634926/5662/d18f6fa1/5b03b779N5c0b196f.png.webp',
              label: '分类一'
            }
            ]
          ]
        })
      })

      // 获取分类页的分类接口
      app.get('/api/classify', (req, res) => {
        switch (req.query.type) {
          case '0':
            res.json({
              data: [{
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img14.360buyimg.com/focus/s140x140_jfs/t11929/135/2372293765/1396/e103ec31/5a1692e2Nbea6e136.jpg',
                label: '华为'
              },
              {
                image: '//img10.360buyimg.com/focus/s140x140_jfs/t12178/348/911080073/4732/db0ad9c7/5a1692e2N6df7c609.jpg',
                label: '荣耀'
              },
              {
                image: '//img20.360buyimg.com/focus/s140x140_jfs/t13759/194/897734755/2493/1305d4c4/5a1692ebN8ae73077.jpg',
                label: '雪梨手机'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img14.360buyimg.com/focus/s140x140_jfs/t11929/135/2372293765/1396/e103ec31/5a1692e2Nbea6e136.jpg',
                label: '华为'
              },
              {
                image: '//img10.360buyimg.com/focus/s140x140_jfs/t12178/348/911080073/4732/db0ad9c7/5a1692e2N6df7c609.jpg',
                label: '荣耀'
              },
              {
                image: '//img20.360buyimg.com/focus/s140x140_jfs/t13759/194/897734755/2493/1305d4c4/5a1692ebN8ae73077.jpg',
                label: '雪梨手机'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img14.360buyimg.com/focus/s140x140_jfs/t11929/135/2372293765/1396/e103ec31/5a1692e2Nbea6e136.jpg',
                label: '华为'
              },
              {
                image: '//img10.360buyimg.com/focus/s140x140_jfs/t12178/348/911080073/4732/db0ad9c7/5a1692e2N6df7c609.jpg',
                label: '荣耀'
              },
              {
                image: '//img20.360buyimg.com/focus/s140x140_jfs/t13759/194/897734755/2493/1305d4c4/5a1692ebN8ae73077.jpg',
                label: '雪梨手机'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img14.360buyimg.com/focus/s140x140_jfs/t11929/135/2372293765/1396/e103ec31/5a1692e2Nbea6e136.jpg',
                label: '华为'
              },
              {
                image: '//img10.360buyimg.com/focus/s140x140_jfs/t12178/348/911080073/4732/db0ad9c7/5a1692e2N6df7c609.jpg',
                label: '荣耀'
              },
              {
                image: '//img20.360buyimg.com/focus/s140x140_jfs/t13759/194/897734755/2493/1305d4c4/5a1692ebN8ae73077.jpg',
                label: '雪梨手机'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img14.360buyimg.com/focus/s140x140_jfs/t11929/135/2372293765/1396/e103ec31/5a1692e2Nbea6e136.jpg',
                label: '华为'
              },
              {
                image: '//img10.360buyimg.com/focus/s140x140_jfs/t12178/348/911080073/4732/db0ad9c7/5a1692e2N6df7c609.jpg',
                label: '荣耀'
              },
              {
                image: '//img20.360buyimg.com/focus/s140x140_jfs/t13759/194/897734755/2493/1305d4c4/5a1692ebN8ae73077.jpg',
                label: '雪梨手机'
              }

              ]
            })
            break
          case '1':
            res.json({
              data: [{
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              }
              ]
            })
            break
          case '2':
            res.json({
              data: [{
                image: '//img14.360buyimg.com/focus/s140x140_jfs/t11929/135/2372293765/1396/e103ec31/5a1692e2Nbea6e136.jpg',
                label: '华为'
              },
              {
                image: '//img14.360buyimg.com/focus/s140x140_jfs/t11929/135/2372293765/1396/e103ec31/5a1692e2Nbea6e136.jpg',
                label: '华为'
              },
              {
                image: '//img14.360buyimg.com/focus/s140x140_jfs/t11929/135/2372293765/1396/e103ec31/5a1692e2Nbea6e136.jpg',
                label: '华为'
              },
              {
                image: '//img14.360buyimg.com/focus/s140x140_jfs/t11929/135/2372293765/1396/e103ec31/5a1692e2Nbea6e136.jpg',
                label: '华为'
              }
              ]
            })
            break
          case '3':
            res.json({
              data: [{
                image: '//img10.360buyimg.com/focus/s140x140_jfs/t12178/348/911080073/4732/db0ad9c7/5a1692e2N6df7c609.jpg',
                label: '荣耀'
              },
              {
                image: '//img10.360buyimg.com/focus/s140x140_jfs/t12178/348/911080073/4732/db0ad9c7/5a1692e2N6df7c609.jpg',
                label: '荣耀'
              },
              {
                image: '//img10.360buyimg.com/focus/s140x140_jfs/t12178/348/911080073/4732/db0ad9c7/5a1692e2N6df7c609.jpg',
                label: '荣耀'
              },
              {
                image: '//img10.360buyimg.com/focus/s140x140_jfs/t12178/348/911080073/4732/db0ad9c7/5a1692e2N6df7c609.jpg',
                label: '荣耀'
              }
              ]
            })
            break
          case '4':
            res.json({
              data: [{
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              }
              ]
            })
            break
          case '5':
            res.json({
              data: [{
                image: '//img20.360buyimg.com/focus/s140x140_jfs/t13759/194/897734755/2493/1305d4c4/5a1692ebN8ae73077.jpg',
                label: '雪梨手机'
              },
              {
                image: '//img20.360buyimg.com/focus/s140x140_jfs/t13759/194/897734755/2493/1305d4c4/5a1692ebN8ae73077.jpg',
                label: '雪梨手机'
              },
              {
                image: '//img20.360buyimg.com/focus/s140x140_jfs/t13759/194/897734755/2493/1305d4c4/5a1692ebN8ae73077.jpg',
                label: '雪梨手机'
              },
              {
                image: '//img20.360buyimg.com/focus/s140x140_jfs/t13759/194/897734755/2493/1305d4c4/5a1692ebN8ae73077.jpg',
                label: '雪梨手机'
              }
              ]
            })
            break
          case '6':
            res.json({
              data: [{
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              },
              {
                image: '//img30.360buyimg.com/focus/s140x140_jfs/t13411/188/926813276/3945/a4f47292/5a1692eeN105a64b4.png',
                label: '小米'
              }
              ]
            })
            break
        }
      })
    }
  },
  css: {
    loaderOptions: {
      stylus: {
        'resolve url': true,
        'import': [
          './src/theme'
        ]
      }
    }
  },

  pluginOptions: {
    'cube-ui': {
      postCompile: true,
      theme: true
    }
  }
}
